from flask import Flask, request, redirect, url_for
#Flask HTTP方法

app = Flask(__name__)


#HTTP协议是全球网络数据通信的基础。该协议定义了从特定URL中检索数据的不同方法。
#打开templates中的login.html页面访问
#打开templates中的login.html页面中改为method = "get"或method = "post"尝试
@app.route('/success/<name>')
def success(name):
	return 'welcome %s' % name


@app.route('/login', methods = ['POST', 'GET'])
def login():
	if request.method == 'POST':
		user = request.form['nm'] #name = "nm"
		return redirect(url_for('success', name = user))
	else:
		user = request.args.get('nm') #name = "nm"
		return redirect(url_for('success', name = user))


if __name__ == '__main__':
	app.run(debug = True)